import request from '@/utils/request';
import { AxiosPromise } from 'axios';
import { MaterialCommonVO, MaterialCommonForm, MaterialCommonQuery } from '@/api/goods/common/types';

/**
 * 查询素材列表
 * @param query
 * @returns {*}
 */

export const listMaterialCommon = (query?: MaterialCommonQuery): AxiosPromise<MaterialCommonVO[]> => {
  return request({
    url: '/order/materialCommon/list',
    method: 'get',
    params: query
  });
};

/**
 * 查询素材详细
 * @param id
 */
export const getMaterialCommon = (id: string | number): AxiosPromise<MaterialCommonVO> => {
  return request({
    url: '/order/materialCommon/' + id,
    method: 'get'
  });
};

/**
 * 查询素材详细
 */
export const getMaterialCommonAllList = (): AxiosPromise<MaterialCommonVO> => {
  return request({
    url: '/order/materialCommon/allList',
    method: 'get'
  });
};

/**
 * 新增素材
 * @param data
 */
export const addMaterialCommon = (data: MaterialCommonForm) => {
  return request({
    url: '/order/materialCommon',
    method: 'post',
    data: data
  });
};

/**
 * 修改素材
 * @param data
 */
export const updateMaterialCommon = (data: MaterialCommonForm) => {
  return request({
    url: '/order/materialCommon',
    method: 'put',
    data: data
  });
};

/**
 * 删除素材
 * @param id
 */
export const delMaterialCommon = (id: string | number | Array<string | number>) => {
  return request({
    url: '/order/materialCommon/' + id,
    method: 'delete'
  });
};

/**
 * 状态修改
 * @param materialCommonId 客户端id
 * @param status 状态
 */
export function changeStatus(materialCommonId: string, status: string) {
  const data = {
    materialCommonId,
    status
  };
  return request({
    url: '/order/materialCommon/changeStatus',
    method: 'put',
    data: data
  });
}

export default {
  list:listMaterialCommon,
  get:getMaterialCommon,
  add:addMaterialCommon,
  update:updateMaterialCommon,
  del:delMaterialCommon,
  getMaterialCommonAllList:getMaterialCommonAllList
}